<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
    <meta name="renderer" content="webkit">
    <title></title>
    <link rel="stylesheet" href="/css/pintuer.css">
    <link rel="stylesheet" href="/css/admin.css">
    <script src="/js/jquery.js"></script>
    <script src="/js/pintuer.js"></script>
    <script src="/js/vuejs-2.5.16.js"></script>
    <script src="/js/axios-0.18.0.js"></script>
    <!-- 引入样式 -->
    <link rel="stylesheet" href="/element-ui/lib/theme-chalk/index.css">
    <!-- 引入组件库 -->
    <script src="/element-ui/lib/index.js"></script>


</head>
<body>
<div class="panel admin-panel" id="commentListDiv">
    <div class="panel-head"><strong class="icon-reorder"> 评论列表</strong> <a href="" style="float:right; display:none;">添加字段</a>
    </div>
    <div class="padding border-bottom">
        <form>
            <ul class="search" style="padding-left:10px;">
                <li>搜索：</li>
<!--                <li>-->
<!--                    <select name="cid" class="input" style="width:200px; line-height:17px;" v-model="cid">-->
<!--                        <option value="">请选择分类</option>-->
<!--                        <option value="0">特色的</option>-->
<!--                        <option value="1">高观看率</option>-->
<!--                        <option value="2">高评分</option>-->
<!--                        <option value="3">最新上映</option>-->
<!--                    </select>-->
<!--                </li>-->
                <li>
                    <input type="text" placeholder="请输入电影名称" name="moviesTitle" class="input"
                           style="width:250px; line-height:17px;display:inline-block" v-model="moviesTitle"/></li>
                <li>
                    <input type="text" placeholder="请输入发布人昵称" name="creatorName" class="input"
                           style="width:250px; line-height:17px;display:inline-block" v-model="creatorName"/>
                    <a class="button border-main icon-search" @click="findByPage()"> 搜索</a></li>
            </ul>
        </form>
    </div>
    <table class="table table-hover text-center">
        <tr>
            <th width="5%">选择</th>
            <th>影视名称</th>
            <th>评论人昵称</th>
            <th>评论时间</th>
            <th>评论内容</th>
            <th width="410">操作</th>
        </tr>

        <tr v-for="comment in pagination.list">
            <td style="text-align:left; padding-left:10px;"><input type="checkbox" name="ids" v-model="ids" :value="comment.id" /></td>
            <td v-text="comment.title">{{comment.title}}</td>
            <td v-text="comment.creatorName">{{comment.creatorName}}</td>
            <td v-if="comment.time">{{comment.time}}</td>
            <td v-text="comment.content">{{comment.content}}</td>
            <td>
                <div class="button-group">
                    <a class="button border-red" href="javascript:void(0)" @click="deleteById(comment.id)">
                        <span class="icon-trash-o"></span>删除</a>
                </div>
            </td>
        </tr>

        <tr>
            <td colspan="7" style="text-align:left;padding-left:20px;">
                <a href="javascript:void(0)" class="button border-red icon-trash-o" style="padding:5px 15px;" @click="deleteBatch()"> 批量删除</a>
                <span>总记录数：{{pagination.total}}</span>
            </td>
        </tr>
        <tr>
            <td colspan="8">
                <div class="pagelist" >
                    <!--分页组件-->
                    <el-pagination
                            @size-change="handleSizeChange"
                            @current-change="handleCurrentChange"
                            :current-page="pagination.pageNum"
                            :page-size="pagination.pageSize"
                            :total="pagination.total"
                            background
                            layout="prev, pager, next">
                    </el-pagination>
                </div>
            </td>
        </tr>
    </table>
</div>
<script type="text/javascript">
    const app = new Vue({
        el: '#commentListDiv',
        data: {
            ids:[],
            moviesTitle:"",
            creatorName:"",
            pagination: { // 分页对象
                pageNum: 1,
                pageSize: 5,
                total: 20,
                list: []
            },
        },
        methods: {
            // 分页查询
            findByPage(page) {
                axios.get("/comments/list",{
                    params:{
                        pageNum:this.pagination.pageNum,
                        pageSize:this.pagination.pageSize,
                        creatorName:this.creatorName,
                        moviesTitle:this.moviesTitle,
                    }
                }).then(resp=>{
                    if (resp.data.code = 1){
                        this.pagination.total=resp.data.data.total;
                        this.pagination.list=resp.data.data.list;
                    }else{
                        alert(resp.data.msg);
                    }
                });
            },
            //当前页改变时调用的方法
            handleCurrentChange(pageNum) {
                //将最新页码赋值给分页对象的当前页码
                this.pagination.pageNum = pageNum;
                //重新发起分页请求
                this.findByPage();
            },
            //改变每页大小时调用的方法
            handleSizeChange(pageSize) {
                //将最新的每页大爱小赋值给分页对象的当前页码
                this.pagination.pageSize = pageSize;
                //重新发起分页请求
                this.findByPage();
            },
            //单个删除
            deleteById(id){
                if(confirm("你确定要删除吗?")){
                    axios.delete("/comments/deleteById?id="+id).then(resp=>{
                        if (resp.data.code == 1) {
                            const totalPage = Math.ceil((this.pagination.total - 1) / this.pagination.pageSize) // 计算总页数
                            this.pagination.pageNum = this.pagination.pageNum > totalPage ? totalPage : this.pagination.pageNum;
                            this.pagination.pageNum = this.pagination.pageNum < 1 ? 1 : this.pagination.pageNum;
                            this.findByPage();
                        }else{
                            alert(resp.data.msg);
                        }
                    });
                }
            },
            //批量删除
            deleteBatch(){
                if(this.ids.length>0){
                    console.log(this.ids);
                    if(confirm("您确定要删除这些吗?")){
                        axios.delete("/comments/deleteByIds?ids="+this.ids).then(resp=>{
                            if (resp.data.code == 1) {
                                const totalPage = Math.ceil((this.pagination.total - this.ids.length) / this.pagination.pageSize) // 计算总页数
                                this.pagination.pageNum = this.pagination.pageNum > totalPage ? totalPage : this.pagination.pageNum;
                                this.pagination.pageNum = this.pagination.pageNum < 1 ? 1 : this.pagination.pageNum;
                                this.findByPage();
                            }else{
                                alert(resp.data.msg);
                            }
                        });
                    }
                }
            },
            //单个删除
            // toBanner(id){
            //     if(confirm("你确定要添加到banner中吗?")){
            //         axios.post("/movies/save2Banner?id="+id).then(resp=>{
            //             if (resp.data.code == 1) {
            //                 this.findByPage();
            //             }else{
            //                 alert(resp.data.msg);
            //             }
            //         });
            //     }
            // },
        },
        //vue对象创建成功之后要做的事情,可以简单的理解为页面加载成功事件
        created:function (){
            this.findByPage();
        }
    })
</script>
<script src="/js/verify.js"></script>
</body>
</html>